#include "server.h"

//server->client[client_index].root_dir
//server->client[client_index].current_dir
//dirname
int handle_mkdir(int net_fd, ClientInfo *client, const char* dirname) {

    client->socket = net_fd;

    Message response = {0};

    char temp_path[PATH_MAX];
    strcpy(temp_path,client->root_dir);
    strcat(temp_path,client->current_dir);
    strcat(temp_path,dirname);

    if (mkdir(temp_path, 0755) == 0) {
        response.type = MSG_TYPE_SUCCESS;
        response.length = snprintf(response.data, sizeof(response.data), "成功创建目录: %s", dirname);
    } else {
        response.type = MSG_TYPE_FAIL;
        response.length = snprintf(response.data, sizeof(response.data), "创建目录失败: %s", dirname);
    }

    if (send_message(client->socket, &response) < 0) {
        perror("发送mkdir响应失败");
        return -1;
    }

    return 0;
}
